<%--
  Created by IntelliJ IDEA.
  User: LJJ
  Date: 2023/3/8
  Time: 17:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8"/>
    <title>查询仓库</title>

    <link href="css/all.css" rel="stylesheet" type="text/css">
    <link href="js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="js/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">

</head>
<body>
<script>
    var statusList = ["已删除", "待收取", "在库中", "运输中", "司机取件", "确认送达"];
</script>
<div>
    <div class="div_find">

        <p><label class="find_labela">运单号：</label><input class="find_input" id="waybillNo"/>
            <%--        <option>全部</option>--%>
            <%--        <option>十一届</option>--%>
            <%--        <option>十二届</option>--%>
            <%--        <option>十三届</option>--%>
            <%--        <option>十四届</option>--%>
            <%--        <option>十五届</option>--%>

            </input><label class="find_labela">寄件类型：</label><select class="find_input" id="mailType">


            </select>
            <label class="find_labela">仓库：</label><select class="find_input" id="warehouseId">

            </select>

            <input type="button" value="搜索一下" onclick="showWaybill(1)" class="find_but" id="but_close">
            <input type="button" value="重置" onclick="clean()" class="find_but" id="but_close01"></p></div>
    <p class="p_but">

        <i class="down_i"></i><a href="#" class="add_a">导出</a>
        <i class="print_i"></i><a href="#" class="add_a">打印</a>
    </p>

    <p>
    <table id="table" class="table" style="margin: 0 auto">
    </table>
    </p>
    <div id="page">

    </div>


</div>
<!-- 创建市场活动的模态窗口 -->
<div class="modal fade" id="test1" role="dialog">
    <div class="modal-dialog" role="document" style="width: 85%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel1">修改运单信息</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" role="form" id="createActivityForm">

                    <div class="form-group">
                        <label for="waybillNo1" class="col-sm-2 control-label">运单号</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="waybillNo1" readonly="readonly">

                            <%--                        <select class="form-control" id="create-marketActivityOwner">--%>
                            <%--<option>zhangsan</option>
                            <option>lisi</option>
                            <option>wangwu</option>--%>

                            <%--                        </select>--%>
                        </div>
                        <label for="mailType1" class="col-sm-2 control-label">寄件类型<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <select class="form-control" id="mailType1">

                            </select>
                        </div>


                    </div>

                    <div class="form-group">
                        <label for="senderName" class="col-sm-2 control-label">寄件人<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="senderName">
                        </div>
                        <label for="senderPhone" class="col-sm-2 control-label">寄件人电话<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" onmouseout="hidePhoneError()" id="senderPhone"><span
                                id="senderPhoneError" hidden="hidden" style="font-size: 15px; color: red;">号码不规范</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="senderAddress" class="col-sm-2 control-label">寄件人地址<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="senderAddress">
                        </div>
                        <label for="recipientName" class="col-sm-2 control-label">收件人姓名<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="recipientName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="recipientPhone" class="col-sm-2 control-label">收件人电话<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" onmouseout="hidePhoneError1()"
                                   id="recipientPhone"><span id="recipientPhoneError" hidden="hidden"
                                                             style="font-size: 15px; color: red;">号码不规范</span>
                        </div>
                        <label for="recipientAddress" class="col-sm-2 control-label">收件人地址<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="recipientAddress">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mailCost" class="col-sm-2 control-label">费用</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="mailCost" readonly="readonly">
                        </div>
                        <label for="status" class="col-sm-2 control-label">状态<span style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="status" readonly="readonly">
                            </input>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="warehouseId1" class="col-sm-2 control-label">仓库名</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="warehouseId1" readonly="readonly">
                        </div>
                        <label for="driverName" class="col-sm-2 control-label">运件司机</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="driverName" readonly="readonly">
                        </div>

                    </div>

                    <%--                <span id="activityMsg" style="color: red;position: absolute;left: 180px"></span>--%>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="saveActivityBtn" type="button" class="btn btn-primary" onclick="updateWaybill()">保存</button>
            </div>
        </div>
    </div>
</div>


<script src="js/jquery/jQuery-2.2.0.min.js"></script>
<script src="js/bstable/js/bootstrap.min.js"></script>
<script src="js/bstable/js/bootstrap-table.js"></script>
<script src="js/bstable/js/bootstrap-table-zh-CN.min.js"></script>
<script src="js/date/js/laydate.js"></script>

<script>
    $.ajax({
        url: "queryMailName.do",
        type: "POST",
        dataType: "json",
        success: function (data) {
            var str = "";
            var str1 = "";
            str += "<option value='0' selected='selected' >全部</option>";
            for (var i = 0; i < data.length; i++) {
                str1 += "<option value='" + data[i].mailType + "'>" + data[i].mailTypeName + "</option>"
            }
            str += str1;
            $("#mailType").html(str);
            $("#mailType1").html(str1);
        }
    })

    $.ajax({
        url: "queryWarehouseName.do",
        type: "POST",
        dataType: "json",
        success: function (data) {
            var str = "";
            str += "<option value='0' selected='selected' >全部</option>";
            for (var i = 0; i < data.length; i++) {
                str += "<option value='" + data[i].id + "'>" + data[i].name + "</option>"
            }
            $("#warehouseId").html(str);

        }
    })

    showWaybill(1);

    function showWaybill(pageNum) {

        $.ajax({
            url: "queryWaybill.do",
            type: "POST",
            data: {
                "waybillNo": $("#waybillNo").val(),
                "mailType": $("#mailType option:selected").val(),
                "warehouseId": $("#warehouseId option:selected").val(),
                "pageNum": pageNum,
                "pageSize": 10
            },
            dataType: "json",
            success: function (datas) {
                var str = "";
                str += "<tr><th>运单号</th><th>仓库名</th><th>寄件类型</th><th>寄件人姓名</th><th>寄件人电话</th><th>寄件人地址</th><th>收件人姓名</th><th>收件人电话</th><th>收件人地址</th><th>运件司机</th><th>费用</th><th>状态</th><th>操作</th></tr>"
                var data = datas.list;
                for (var i = 0; i < data.length; i++) {
                    str += "<tr>"
                    str += "<td>" + data[i].waybillNo + "</td>"
                    str += "<td>" + data[i].warehouseName + "</td>"
                    str += "<td>" + data[i].mailType + "</td>"
                    str += "<td>" + data[i].senderName + "</td>"
                    str += "<td>" + data[i].senderPhone + "</td>"
                    str += "<td>" + data[i].senderAddress + "</td>"
                    str += "<td>" + data[i].recipientName + "</td>"
                    str += "<td>" + data[i].recipientPhone + "</td>"
                    str += "<td>" + data[i].recipientAddress + "</td>"
                    if (data[i].driverName == null || data[i].driverName == 0) {
                        str += "<td>无</td>"
                    } else {
                        str += "<td>" + data[i].driverName + "</td>"
                    }

                    str += "<td>" + data[i].mailCost + "</td>"
                    str += "<td>" + statusList[data[i].status] + "</td>"
                    str += "<td><a href='#' onclick='update(" + JSON.stringify(data[i]) + ")'>修改</a><a href='#' onclick='deleteWaybill(" + data[i].waybillNo + ")'>删除</a></td>"
                }
                $("#table").html(str)
                var cutPage = "";
                for (var i = 1; i <= datas.pages; i++) {
                    cutPage += "<a href='#' onclick='showWaybill(" + i + ")'>" + i + "</a>&nbsp"
                }
                $("#page").html(cutPage)

            }

        })
    }

    function clean() {
        $("#waybillNo").val("");
        $("#mailType").val("0");
        $("#warehouseId").val("0");
        showWaybill(1);
    }

    function update(data) {
        hidePhoneError()
        hidePhoneError1()
        var data1 = eval(data);
        $("#waybillNo1").val(data1.waybillNo)
        // $("#mailType1").val(data1.mailType)
        $("#mailType1").find("option:contains(" + data1.mailType + ")").attr("selected", true);
        $("#senderName").val(data1.senderName)
        $("#senderPhone").val(data1.senderPhone)
        $("#senderAddress").val(data1.senderAddress)
        $("#recipientName").val(data1.recipientName)
        $("#recipientPhone").val(data1.recipientPhone)
        $("#recipientAddress").val(data1.recipientAddress)
        $("#mailCost").val(data1.mailCost)
        $("#status").val(statusList[data1.status])
        $("#warehouseId1").val(data1.warehouseName)
        $("#driverName").val(data1.driverName)

        $("#test1").modal("show")
    }

    function deleteWaybill(waybillNo) {
        $.ajax({
            url: "deleteWaybill.do",
            type: "post",
            data: {
                "waybillNo": waybillNo
            },
            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == "1") {
                    window.location.reload()
                }
            }
        })
    }

    function updateWaybill() {

        var count = 0
        var reg = /^[1]\d{10}/
        const senderName = $("#senderName")
        const senderPhone = $("#senderPhone")
        const senderAddress = $("#senderAddress")
        const recipientName = $("#recipientName")
        const recipientPhone = $("#recipientPhone")
        const recipientAddress = $("#recipientAddress")

        if (senderName.val() == "" || senderPhone.val() == "" || senderAddress.val() == "") {
            count += 1
        }
        if (recipientName.val() == "" || recipientPhone.val() == "" || recipientAddress.val() == "") {
            count += 1
        }
        if (!reg.test(senderPhone.val())) {
            count += 1
            $("#senderPhoneError").show()
        }
        if (!reg.test(recipientPhone.val())) {
            count += 1
            $("#recipientPhoneError").show()
        }

        if (count > 0) {
            alert("请规范填写")
            return false
        }

        $.ajax({
            url: "updateWaybill.do",
            type: "POST",
            data: {
                "waybillNo": $("#waybillNo1").val(),
                "mailType": $("#mailType1").val(),
                "senderName": $("#senderName").val(),
                "senderPhone": $("#senderPhone").val(),
                "senderAddress": $("#senderAddress").val(),
                "recipientName": $("#recipientName").val(),
                "recipientPhone": $("#recipientPhone").val(),
                "recipientAddress": $("#recipientAddress").val(),
                // "status":$("#status").val(),
                // "warehouseId":$("#recioientAddress"),
            },

            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == "1") {
                    window.location.reload()
                }
            }
        })
    }

    function hidePhoneError() {
        $("#senderPhoneError").hide()
    }

    function hidePhoneError1() {
        $("#recipientPhoneError").hide()
    }

</script>


</body>
</html>

